home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / gtlayout-source.lha / LTP_CreateGadgets.c < prev    next >
C/C++ Source or Header  |  1995-09-24  |  7KB  |  254 lines

  1. /*  GadTools layout toolkit
  2. **
  3. **  Copyright © 1993-1995 by Olaf `Olsen' Barthel
  4. **  Freely distributable.
  5. */
  6.  
  7. #include "gtlayout_global.h"
  8.  
  9. VOID __regargs
  10. LTP_CreateGadgets(LayoutHandle *Handle,struct IBox *Bounds,LONG Left,LONG Top,LONG PlusWidth,LONG PlusHeight)
  11. {
  12.     if(!Handle -> Failed)
  13.     {
  14.         LONG    OldInterWidth    = Handle -> InterWidth,
  15.             OldInterHeight    = Handle -> InterHeight;
  16.  
  17.         BOOLEAN    Fits;
  18.         BOOLEAN    Cloned = FALSE;
  19.         WORD    Attempt = 3,ScaleAttempt = 6;
  20. /*
  21.         if(!V39 && (Handle -> RPort . TxFlags & FPF_PROPORTIONAL))
  22.         {
  23.             LTP_Rescale(Handle,FALSE,FALSE);
  24.  
  25.             Handle -> Rescaled = FALSE;
  26.         }
  27. */
  28.         do
  29.         {
  30.             LTP_LayoutGroup(Handle,Handle -> TopGroup);
  31.             LTP_PlaceGroups(Handle,Handle -> TopGroup,Left,Top);
  32.  
  33.             Fits = TRUE;
  34.  
  35.             DB(kprintf("TopGroup->Width %ld + PlusWidth %ld = %ld > Bounds->Width %ld\n",Handle -> TopGroup -> Width,PlusWidth,Handle -> TopGroup -> Width + PlusWidth,Bounds -> Width));
  36.  
  37.             if(Handle -> TopGroup -> Width + PlusWidth > Bounds -> Width)
  38.             {
  39.                 DB(kprintf("%ld > Screen->Width %ld\n",Handle -> TopGroup -> Width + PlusWidth,Handle -> Screen -> Width));
  40.  
  41.                 if(Handle -> TopGroup -> Width + PlusWidth > Handle -> Screen -> Width)
  42.                 {
  43.                     Fits = FALSE;
  44.  
  45.                     DB(kprintf("TopGroup->Height %ld + PlusHeight %ld = %ld > Bounds->Height %ld\n",Handle -> TopGroup -> Height,PlusHeight,Handle -> TopGroup -> Height + PlusHeight,Bounds -> Height));
  46.  
  47.                     if(Handle -> TopGroup -> Height + PlusHeight > Bounds -> Height)
  48.                     {
  49.                         DB(kprintf("rescale TRUE,TRUE\n"));
  50.  
  51.                         LTP_Rescale(Handle,TRUE,TRUE);
  52.                     }
  53.                     else
  54.                     {
  55.                         DB(kprintf("rescale TRUE,FALSE\n"));
  56.  
  57.                         LTP_Rescale(Handle,TRUE,FALSE);
  58.                     }
  59.  
  60.                     ScaleAttempt--;
  61.  
  62.                     Left        = Left        - OldInterWidth        + Handle -> InterWidth;
  63.                     Top        = Top        - OldInterHeight    + Handle -> InterHeight;
  64.                     PlusWidth    = PlusWidth    - OldInterWidth        + Handle -> InterWidth;
  65.                     PlusHeight    = PlusHeight    - OldInterHeight    + Handle -> InterHeight;
  66.                     OldInterWidth    = Handle -> InterWidth;
  67.                     OldInterHeight    = Handle -> InterHeight;
  68.                 }
  69.             }
  70.             else
  71.             {
  72.                 DB(kprintf("TopGroup->Height %ld + PlusHeight %ld = %ld > Bounds->Height %ld\n",Handle -> TopGroup -> Height,PlusHeight,Handle -> TopGroup -> Height + PlusHeight,Bounds -> Height));
  73.  
  74.                 if(Handle -> TopGroup -> Height + PlusHeight > Bounds -> Height)
  75.                 {
  76.                     DB(kprintf("TopGroup->Height %ld + PlusHeight %ld = %ld > Screen->Height %ld\n",Handle -> TopGroup -> Height,PlusHeight,Handle -> TopGroup -> Height + PlusHeight,Handle -> Screen -> Height));
  77.  
  78.                     if(Handle -> TopGroup -> Height + PlusHeight > Handle -> Screen -> Height)
  79.                     {
  80.                         DB(kprintf("rescale FALSE,TRUE\n"));
  81.                         Fits = FALSE;
  82.  
  83.                         LTP_Rescale(Handle,FALSE,TRUE);
  84.  
  85.                         Left        = Left        - OldInterWidth        + Handle -> InterWidth;
  86.                         Top        = Top        - OldInterHeight    + Handle -> InterHeight;
  87.                         PlusWidth    = PlusWidth    - OldInterWidth        + Handle -> InterWidth;
  88.                         PlusHeight    = PlusHeight    - OldInterHeight    + Handle -> InterHeight;
  89.                         OldInterWidth    = Handle -> InterWidth;
  90.                         OldInterHeight    = Handle -> InterHeight;
  91.  
  92.                         ScaleAttempt--;
  93.                     }
  94.                 }
  95.             }
  96.  
  97.             DB(kprintf("ok\n"));
  98.  
  99. #ifdef DO_CLONING
  100.             DB(kprintf("1) failed %ld cloned %ld cloningpermitted %ld\n",Handle -> Failed,Cloned,Handle -> CloningPermitted));
  101.  
  102.             if(Handle -> Failed && !Cloned && Handle -> CloningPermitted)
  103.             {
  104.                 if(LTP_PrepareCloning(Handle))
  105.                 {
  106.                     Bounds = &Handle -> CloneExtra -> Bounds;
  107.  
  108.                     Cloned = TRUE;
  109.                 }
  110.             }
  111. #endif
  112.  
  113.             if(Attempt > 0 && Fits && !Handle -> Rescaled && !Cloned && !Handle -> Failed && (Handle -> GrowView || (Handle -> ResizeView && Handle -> Window)))
  114.             {
  115.                 LONG        Width    = Handle -> TopGroup -> Width    + PlusWidth,
  116.                         Height    = Handle -> TopGroup -> Height    + PlusHeight;
  117.                 ObjectNode    *View;
  118.  
  119.                 Attempt--;
  120.  
  121.                 if(Handle -> GrowView)
  122.                     View = Handle -> GrowView;
  123.                 else
  124.                     View = Handle -> ResizeView;
  125.  
  126.                  if(Bounds -> Width != Width || Bounds -> Height != Height)
  127.                 {
  128.                     LONG    PlusChars,
  129.                         PlusLines;
  130.                     WORD    GlyphWidth,
  131.                         GlyphHeight;
  132.                     WORD    AvailableWidth,
  133.                         AvailableHeight;
  134.  
  135.                     AvailableWidth    = Bounds -> Width    - Width;
  136.                     AvailableHeight    = Bounds -> Height    - Height;
  137.  
  138.                     if(View -> Special . List . TextAttr)
  139.                     {
  140.                         GlyphWidth    = View -> Special . List . FixedGlyphWidth;
  141.                         GlyphHeight    = View -> Special . List . FixedGlyphHeight;
  142.                     }
  143.                     else
  144.                     {
  145.                         GlyphWidth    = Handle -> GlyphWidth;
  146.                         GlyphHeight    = Handle -> RPort . TxHeight;
  147.                     }
  148.  
  149.                     if(View -> Special . List . MaxGrowX && Handle -> GrowView)
  150.                     {
  151.                         PlusChars = AvailableWidth / GlyphWidth;
  152.  
  153.                         if(PlusChars > 0 && View -> Chars + PlusChars > View -> Special . List . MaxGrowX)
  154.                             PlusChars = View -> Special . List . MaxGrowX - View -> Chars;
  155.  
  156.                         if(PlusChars < 0)
  157.                             PlusChars = 0;
  158.                     }
  159.                     else
  160.                     {
  161.                         if(View -> Special . List . ResizeX && !Handle -> GrowView)
  162.                         {
  163.                             if(AvailableWidth < 0)
  164.                                 PlusChars = (AvailableWidth - (GlyphWidth + 1)) / GlyphWidth;
  165.                             else
  166.                                 PlusChars = AvailableWidth / GlyphWidth;
  167.                         }
  168.                         else
  169.                             PlusChars = 0;
  170.                     }
  171.  
  172.                     if(View -> Special . List . MaxGrowY && Handle -> GrowView)
  173.                     {
  174.                         PlusLines = AvailableHeight / GlyphHeight;
  175.  
  176.                         if(PlusLines > 0 && View -> Lines + PlusLines > View -> Special . List . MaxGrowY)
  177.                             PlusLines = View -> Special . List . MaxGrowY - View -> Lines;
  178.  
  179.                         if(PlusLines < 0)
  180.                             PlusLines = 0;
  181.                     }
  182.                     else
  183.                     {
  184.                         if(View -> Special . List . ResizeY && !Handle -> GrowView)
  185.                         {
  186.                             if(AvailableHeight < 0)
  187.                                 PlusLines = (AvailableHeight - (GlyphHeight + 1)) / GlyphHeight;
  188.                             else
  189.                                 PlusLines = AvailableHeight / GlyphHeight;
  190.                         }
  191.                         else
  192.                             PlusLines = 0;
  193.                     }
  194.  
  195.                     if(PlusChars != 0 || PlusLines != 0)
  196.                     {
  197.                         View -> Chars += PlusChars;
  198.                         View -> Lines += PlusLines;
  199.  
  200.                         LTP_ResetGroups(Handle -> TopGroup);
  201. /*
  202.                         if(!V39 && (Handle -> RPort . TxFlags & FPF_PROPORTIONAL))
  203.                         {
  204.                             LTP_Rescale(Handle,FALSE,FALSE);
  205.  
  206.                             Handle -> Rescaled = FALSE;
  207.                         }
  208. */
  209.                         Fits = FALSE;
  210.                     }
  211.                 }
  212.  
  213.                 Handle -> GrowView = NULL;
  214.             }
  215.  
  216.             DB(kprintf("fits %ld handle->failed %ld attempt %ld\n",Fits,Handle->Failed,Attempt));
  217.         }
  218.         while(!Fits && !Handle -> Failed && ScaleAttempt > 0);
  219.  
  220. #ifdef DO_CLONING
  221.         if(!Handle -> Failed && !Cloned && Handle -> CloningPermitted && !Fits && ScaleAttempt <= 0)
  222.         {
  223.             if(LTP_PrepareCloning(Handle))
  224.             {
  225.                 LTP_LayoutGroup(Handle,Handle -> TopGroup);
  226.                 LTP_PlaceGroups(Handle,Handle -> TopGroup,Left,Top);
  227.  
  228.                 Cloned = TRUE;
  229.             }
  230.         }
  231.  
  232.         DB(kprintf("2) failed %ld cloned %ld\n",Handle -> Failed,Cloned));
  233.  
  234.         if(!Handle -> Failed && Cloned)
  235.             LTP_CloneScreen(Handle,Handle -> TopGroup -> Width + PlusWidth,Handle -> TopGroup -> Height + PlusHeight);
  236. #endif
  237.  
  238.         if(!Handle -> Failed)
  239.         {
  240.             if(Handle -> GadgetArray = LTP_Alloc(Handle,sizeof(struct Gadget *) * Handle -> Count))
  241.             {
  242. #ifdef DO_PICKSHORTCUTS
  243.                 LTP_SearchKeys(Handle,Handle -> TopGroup);
  244.                 LTP_SelectKeys(Handle,Handle -> TopGroup);
  245. #endif
  246.                 LTP_LayoutGadgets(Handle,Handle -> TopGroup,Left,Top,PlusWidth,PlusHeight);
  247.  
  248.                 if(Handle -> Failed)
  249.                     LTP_DisposeGadgets(Handle);
  250.             }
  251.         }
  252.     }
  253. }
  254.